﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Achievement.DataModels;
using Achievement.BLL;
using Achievement.BLL.Provider;
using Achievement.Common;
using System.Web.Security;

namespace Achievement.Web.Controllers
{
    public class RegisterController : Controller
    {
        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(Users users, string txtConfirmPWD)
        {
            if (users.PassWord == txtConfirmPWD)
            {
                Users u = UsersProvider.Instance.GetUserByLoginName(users.LoginName);
                if (u == null)
                {
                    users.Roles = 0;
                    users.IsActive = false;
                    UsersProvider.Instance.AddUser(users);
                    //FormsAuthentication.SetAuthCookie(users.LoginName, false);
                    return Content(ATools.OperateAlter("注册成功，请等待管理员审核！"));
                }
                else
                {
                    return Content(ATools.OperateAlter("登录名已经被使用！"));
                }
            }
            else
            {
                return Content(ATools.OperateAlter("密码输入不一致！"));
            }
        }
    }
}
